package com.csv;

import java.io.*;

/**
 * @ClassName CSVReader
 * @Description TODO
 * @Author ZhangY
 * @Date 2020/1/21 10:57
 * @Version 1.0.0
 */
public class CSVReader {
    public static void main(String[] args) {
        BufferedReader reader = null;//换成你的文件名
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader("C:\\Users\\zhangyue26\\Desktop\\PersonDetailTemplate.csv"));
            writer = new BufferedWriter(new FileWriter("C:\\Users\\zhangyue26\\Desktop\\导出.csv"));
            reader.readLine();//第一行信息，为标题信息，不用,如果需要，注释掉
            String line = null;
            while((line=reader.readLine())!=null){
                String item[] = line.split(",");//CSV格式文件为逗号分隔符文件，这里根据逗号切分
                for (int i = 0; i < item.length; i++) {
                    System.out.print(item[i]+"\t");
                    writer.write("\""+item[i]+"\""+",");
                }
                writer.newLine();
                System.out.println();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                if (reader!=null)reader.close();
                if (writer!=null)writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
